package ArrayStudy;

import java.util.Arrays;
import java.util.Scanner;

public class ArrayGrow {
    public static void main(String[] args) {
        int[] a = {1, 3, 5};//3

        System.out.println("Arrays.toString(a) = " + Arrays.toString(a));
        while (true) {
            System.out.println("数组已满，需要扩容吗？Y，N");//n
            Scanner scanner = new Scanner(System.in);
            String ask = scanner.next();//y
            if(ask.equals("N"))
            {
                break;
            }
            System.out.println("请添加一个数据:");
            int num = scanner.nextInt();
            int[] b = new int[a.length + 1];
            for (int i = 0; i < a.length; i++) {
                b[i] = a[i];
            }
            a = b;//a指向新开辟空间 4
            a[a.length - 1] = num;//4  0  1 2 3
        }

       System.out.println("Arrays.toString(a) = " + Arrays.toString(a));






    }
}
